app.service('questionService',['$q','utilService',function($q,utilService){

    //查询问题类型下拉框
    this.getList = function($scope){
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'question/type/list'
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错");
        });
        return deferred.promise;
    }
    //查询ById
    this.findById = function($scope){
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'question/'+ $scope.question.id,
            params:{id:$scope.question.id}
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错");
        });
        return deferred.promise;
    }
    //删除问题
    this.delQuestion = function($scope){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'question/del',
            data:{id:$scope.question.id},
            method:"PUT"
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }
    //新增问题
    this.addQuestion = function($scope){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'question',
            data:$scope.question,
            method:'POST'
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }
    //修改问题
    this.editQuestion = function($scope){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'question',
            data:$scope.question,
            method:'PUT'
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }
    //置顶
    this.toTop = function($scope){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'question/toTop',
            data:{id:$scope.question.id},
            method:"PUT"
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }
}])